Imports System.Data.oledb

Imports Common
Imports Common.Env
Imports StartFrame.DA.Sql
Imports StartPoint.BR.Interfaces
Imports Common.spmc


Public Class LotePruebas
    Inherits Abm
    Implements ILotePrueba

    Private _lotePruebasItems As ItemsLotePruebas

    Sub New()
        MyBase.New(Operador, Password, "walotepruebas", "wcd_lote_pruebas")

        Dim arrayTablasDetalle As New ArrayList()
        arrayTablasDetalle.Add("wld_detalle_pruebas")
        MyBase.setTablasDetalle(arrayTablasDetalle)

        _lotePruebasItems = New ItemsLotePruebas()

    End Sub

    Public Function getItems(ByVal loteId As Integer) As DataSet Implements ILotePrueba.getItems

        Dim ds As DataSet
        Dim paramArrayList As New ArrayList()
        paramArrayList.Add(loteId)
        ds = ExecSPDS(ConnectionString, "wld_detalle_pruebas_consulta", paramArrayList)
        ds.Tables(0).TableName = "wld_detalle_pruebas"
        Return ds

    End Function

    Public Function getEstados() As DataSet Implements ILotePrueba.getEstados

        Dim ds As New DataSet
        Dim c1 As New DataColumn("id", System.Type.GetType("string"))
        Dim c2 As New DataColumn("descripcion", System.Type.GetType("string"))
        ds.Tables.Add("estados_lotes_pruebas")
        ds.Tables(0).Columns.Add(c1)
        ds.Tables(0).Columns.Add(c2)

        Dim row(1) As String
        row(0) = "P"
        row(1) = "Pendiente"
        ds.Tables(0).Rows.Add(row)
        row(0) = "A"
        row(1) = "Prueba Aceptada"
        ds.Tables(0).Rows.Add(row)
        row(0) = "R"
        row(1) = "Prueba Rechazada"
        ds.Tables(0).Rows.Add(row)
        row(0) = "X"
        row(1) = "Rehacer"
        ds.Tables(0).Rows.Add(row)
        Return ds

    End Function

    Public Overloads Overrides Function ActualizarDatos(ByRef paramDataSet As System.Data.DataSet) As Boolean

        Dim tran As OleDbTransaction = Nothing

        Try
            InicializarConexion()

            lnk_cn.Open()
            tran = lnk_cn.BeginTransaction

            'Si se esta eliminando la cabecera primero se borran los detalles
            If Not paramDataSet.Tables(lnk_tablaPrincipal).GetChanges(DataRowState.Deleted) Is Nothing Then
                _lotePruebasItems.ActualizarDatos(paramDataSet, lnk_cn, tran)
                MyBase.ActualizarDatos(paramDataSet, lnk_cn, tran)
            Else
                MyBase.ActualizarDatos(paramDataSet, lnk_cn, tran)
                _lotePruebasItems.ActualizarDatos(paramDataSet, lnk_cn, tran)
            End If

            If paramDataSet.HasErrors Then
                tran.Rollback()
            Else
                tran.Commit()
            End If

        Catch ex As Exception
            tran.Rollback()
            Throw ex

        Finally
            tran = Nothing
            lnk_cn.Close()
            lnk_cn = Nothing

        End Try

    End Function

End Class

Friend Class ItemsLotePruebas
    Inherits StartFrame.BR.Abm

    Sub New()
        MyBase.New(Operador, Password, "wadetallepruebas", "wld_detalle_pruebas")

    End Sub

End Class

